package com.zcoj.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author chenbin
 * @version 1.0
 * @description: TODO
 * @date 2023/4/6 23:15
 */
@Configuration
@EnableAsync
public class ScheduledConfig {

	@Bean
	public TaskExecutor taskExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(5);
		executor.setMaxPoolSize(10);
		executor.setQueueCapacity(25);
		return executor;
	}


	/**
	 * @method: [asyncExecutor]
	 * @param: []
	 * @returns: java.util.concurrent.Executor
	 * @description:   异步线程池
	 * @author: chen.bin
	 * @version: 1.0.0
	 * @date 2023/4/17 18:33
	 **/
	@Bean
	public Executor asyncExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(10);
		executor.setMaxPoolSize(50);
		executor.setQueueCapacity(100);
		executor.setThreadNamePrefix("async-thread-");
		executor.initialize();
		return executor;
	}
}
